package org.icosagon.core.items;

import java.util.Vector;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import org.icosagon.core.Definable;
import org.icosagon.core.magic.Charge;
import org.icosagon.core.magic.Spell;

/**
 *
 * @author Daniel Owens
 */
@XmlRootElement(name="item")
public class Item extends Definable {

    private Vector<Charge> charges = new Vector<Charge>();
    private int hardness = 0;
    private Cost cost = new Cost();
    private int weight = 0;
    
    public Item() {}

    public void addCharge(Charge charge) {
        if(charge != null)
            this.charges.add(charge);
    }

    public void removeCharge(Charge charge) {
        if(charge != null)
            this.charges.remove(charge);
    }

    @XmlElement(name="charges")
    public Vector<Charge> getCharges() {
        return this.charges;
    }

    /**
     * Convience method for returning all of the spells associated with
     * this item.
     * @return
     */
    public Vector<Spell> getSpells() {
        Vector<Spell> spells = new Vector<Spell>();
        for(Charge charge : this.charges)
            spells.add(charge.getSpell());
        return spells;
    }

    public boolean isMagical() {
        if(this.charges.isEmpty() || this.charges == null)
            return false;
        else return true;
    }

    public void setHardness(int value) {
        this.hardness = value;
    }

    @XmlElement(name="hardness", required=false)
    public int getHardness() {
        return this.hardness;
    }

    public void setCost(Cost value) {
        this.cost = value;
    }

    @XmlElement(name="price", required=false)
    public Cost getCost() {
        return this.cost;
    }

    public void setWeight(int value) {
        this.weight = value;
    }

    @XmlElement(name="weight", required=true)
    public int getWeight() {
        return this.weight;
    }
}